# import logging
#
# import pytest
# from py.xml import html
# from pytest_yaml_yoyo.http_session import HttpSession
#
# import static
# from common.utils.log_util.setup_log import get_logger
#
# # logger = get_logger()
# logger = logging.getLogger(__name__)
#
#
# # 设置用例描述表头
# def pytest_html_results_table_header(cells):
#     cells.insert(2, html.th('Description'))
#     cells.pop()
#
#
# # 设置用例描述表格
# def pytest_html_results_table_row(report, cells):
#     cells.insert(2, html.td(report.description))
#     cells.pop()
#
#
# @pytest.hookimpl(hookwrapper=True)
# def pytest_runtest_makereport(item):
#     """
#     用于向测试用例中添加用例的开始时间、内部注释，和失败截图等.
#     :param item:
#     """
#     pytest_html = item.config.pluginmanager.getplugin('html')
#     outcome = yield
#     report = outcome.get_result()
#     report.description = description_html(item.function.__doc__)
#     # 截图
#     # extra = getattr(test_report, 'extra', [])
#     # if test_report.when == 'call' or test_report.when == "setup":
#     #     xfail = hasattr(test_report, 'wasxfail')
#     #     if (test_report.skipped and xfail) or (test_report.failed and not xfail):
#     #         case_path = test_report.nodeid.replace("::", "_") + ".png"
#     #         if "[" in case_path:
#     #             case_name = case_path.split("-")[0] + "].png"
#     #         else:
#     #             case_name = case_path
#     #         img_path = "image/" + case_name.split("/")[-1]
#     #         if img_path:
#     #             html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \
#     #                    'onclick="window.open(this.src)" align="right"/></div>' % img_path
#     #             extra.append(pytest_html.extras.html(html))
#     #     test_report.extra = extra
#
#
# def description_html(desc):
#     """
#     将用例中的描述转成HTML对象
#     :param desc: 描述
#     :return:
#     """
#     if desc is None:
#         return "No case description"
#     desc_ = ""
#     for i in range(len(desc)):
#         if i == 0:
#             pass
#         elif desc[i] == '\n':
#             desc_ = desc_ + ";"
#         else:
#             desc_ = desc_ + desc[i]
#
#     desc_lines = desc_.split(";")
#     desc_html = html.html(
#         html.head(
#             html.meta(name="Content-Type", value="text/html; charset=utf-8")),
#         html.body(
#             [html.p(line) for line in desc_lines]))
#     return desc_html
#
#
# # 仅一次登录
# @pytest.fixture(scope='session', autouse=False)
# def login(requests_session: HttpSession, environ):
#     """全局仅一次登录， 更新session请求头部"""
#     url = environ.config['host']['rabbit_platform'] + static.UriConfig.RABBIT_PLATFORM_LOGIN_URI
#     body = {
#         "username": "admin",
#         "password": "admin1"
#     }
#     response = requests_session.post(url, data=body)
#     headers = {"token": response.json()['result']['token']}
#     requests_session.headers.update(headers)
#     logger.info('获取到的token=' + requests_session.headers['token'])
#
#
# def pytest_collection_modifyitems(items):
#     """解决pytest运行结果中的中文乱码"""
#     for item in items:
#         item.name = item.name.encode("utf-8").decode("unicode_escape", errors='ignore')
#         item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape", errors='ignore')
#
#
# if __name__ == "__main__":
#     print('hello')
#     logger.info('good')
